home *** CD-ROM | disk | FTP | other *** search
- /*
- File: HalfGateway.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- /***********************************|****************************************/
-
- #ifndef __HALFGATEWAY__
- #define __HALFGATEWAY__
-
- #ifndef __BLJSTANDARDINCLUDES__
- #include "BLJStandardIncludes.h"
- #endif
-
- #ifndef __DIRECTOBJECT__
- #include "DirectObject.h"
- #endif
-
- /***********************************|****************************************/
-
- class TLetter;
- class TMailGateway;
- class ATupleKey;
- class ADataItem;
-
- /***********************************|****************************************/
-
- class THalfGateway : public TDirectObject
- {
- public: virtual ~THalfGateway();
-
- virtual ostream& operator >> ( ostream& ) const;
-
-
- TMailGateway* GetGateway () const { return fMailGateway; };
-
- //
- // HALF-GATEWAY SETUP METHODS
- //
- // After all of the half gateways have been created and the MailGateway object is
- // itself setup, it will call each HalfGateway's Setup() method. The halfgateway
- // should do what is necessary to get itself set-up and configured, and then return.
- // The gateway should not initiate any time-consuming activities during set-up.
- //
- virtual Boolean Setup ( TMailGateway& mailGateway, short vRefNum, long dirID, const char* gatewayName );
-
-
- // HALF-GATEWAY RECOVERY METHODS
- //
- // Crash recovery will be performed after Setup and before the Run() method is
- // called. The MailGateway will first call the BeginRecoveryPhase() method, after which
- // the halfgateway may begin crash recovery operations. During this phase, the
- // halfgateway should use the ResendLetter() and RereceiveLetter() methods. The
- // halfgateway will probably create a new thread in BeginRecoveryPhase() and then
- // immediately return, but the half-gateway may choose to perform all operations and
- // just return.
- // Any letter which was previously sent via the SendLetter() method, and
- // which still has at least one responsible recipient for which no recipient status
- // has been returned, should be resent during startup. Letters for which no information
- // about any recipient's status has been returned should be sent with the standard
- // SendLetter() method.
- // The halfgateway must be prepared to accept letters via the ReceiveLetter() and
- // RereceiveLetter() methods during the setup phase. Letters which should be resent
- // will arrive via ReceiveLetter(). Letters which do not need to be resent, but which
- // are resent because they have not been fully acknowledged, will come in through
- // RereceiveLetter(). It is permissible to treat letters which arrive via RereceiveLetter
- // as if they are being received for the first time, with the caveat that doing so may
- // cause some recipients to receive multiple copies of each letter.
- // After the gateway has completed all recovery duties, the method IsRecoveryDone()
- // should begin to return true. The IsRecoveryDone() method may be called before
- // BeginRecoveryPhase() is called. Once all halfgateways have finished their crash recovery,
- // the MailGateway will call the FinishRecoveryPhase() method for each half gateway.
- //
- virtual Boolean BeginRecoveryPhase(void) = 0;
- virtual Boolean IsRecoveryDone(void) = 0;
- virtual Boolean FinishRecoveryPhase(void) = 0;
-
- virtual Boolean ResendLetter (TLetter* letter);
- virtual Boolean RereceiveLetter (TLetter* letter) = 0;
-
- //
- // HALF-GATEWAY OPERATION METHODS
- //
- // Once the half-gateway has been setup and the crash recovery phase has begun,
- // the mailgateway will call the Run() method for each half gateway. This method MUST
- // create at least one new thread (which will perform the functions of the half gateway)
- // and then return. If the gateway has some problem, such that it can not run, Run() should
- // return false; otherwise Run() should return true.
- virtual Boolean Run (void) = 0;
-
- // To send a letter from this halfgateway to a destination half-gateway, use the
- // SendLetter() method. If an error occurs, return false; otherwise return true.
- virtual Boolean SendLetter (TLetter* letter);
-
- // This method will be called by the MailGateway with a letter that this halfgateway
- // needs to handle. If an error occurs, return false; otherwise return true.
- virtual Boolean ReceiveLetter (TLetter* letter) = 0;
-
- // Eventually, the gateway will need to be shut down. The MailGateway will call each
- // halfgateway's PrepareToShutDown() method. This method should do what is possible to
- // shut the gateway down. The inHowManySeconds is supplied as a request for what speed
- // should be used; it does not require a commitment to be ready to shut down in that time.
- // Typically, shutting down would involve handling any letters already in the receive pipeline,
- // but would not result in generating new letters to the destination halfgateway.
- // During this time, the IsHalfGatewayShuttingDown() function should return true. When this
- // halfgateway is prepared to shut down, IsHalfGatewayReadyToShutDown() should return true.
- // The method CancelHalfGatewayShutdown() may be called by the MailGateway after
- // PrepareToShutdown(), and would indicate that the MailGateway is no longer shutting down
- // and so all operations can continue. Finally, after all of the halfgateways have
- // reached the prepared-to-shutdown-phase (as indicated by each returning true to
- // IsHalfGatewayReadyToShutDown() method), the MailGateway will call the ShutDown() method
- // for each one. After this is done, starting up the gateway again would require that
- // the sequence from BeginRecoveryPhase() onward be called again.
- virtual Boolean PrepareToShutDown(long inHowManySeconds);
- virtual Boolean IsHalfGatewayShuttingDown(void);
- virtual Boolean IsHalfGatewayReadyToShutDown(void);
- virtual Boolean CancelHalfGatewayShutdown (void);
- virtual Boolean ShutDown(void);
-
- virtual Boolean GetStatusStr ( Str255& statusStr ) const;
-
-
- virtual Boolean HandleMonitoringEvent ( const ADataItem& event );
-
- //
- // CONFIGURATION / SETUP METHODS
- // =============================
- //
- virtual Boolean GetConfigItem(const ATupleKey& key, ADataItem& );
- virtual Boolean SetConfigItem(const ATupleKey& key, const ADataItem& );
- virtual Boolean DeleteConfigItem(const ATupleKey& key);
- virtual Boolean GetNthConfigKey(unsigned long index, ATupleKey& key);
-
- //
- // STATUS REPORTING / ERROR REPORTING OPTIONS
- // ==========================================
- //
- virtual Boolean GetStatusItem(const ATupleKey& key, ADataItem&);
- virtual Boolean SetStatusItem(const ATupleKey& key, const ADataItem& );
-
- protected: THalfGateway ();
- THalfGateway ( TMailGateway& );
-
- TMailGateway* fMailGateway;
- };
-
- /***********************************|****************************************/
-
- #endif // __HALFGATEWAY__
-
-
-